function FindProxyForURL(url, host){
var a = new Array("operachina.com");
for (i in a) {if(shExpMatch(url.toLowerCase(),"*" + a[i].toLowerCase() + "*")){return "PROXY 59.151.106.253:80";};};
var e = new Array("xiami.net");
for (i in e) {if(shExpMatch(url.toLowerCase(),"*" + e[i].toLowerCase() + "*")){return "PROXY 127.0.0.1:8087";};};
var c = new Array("amazonaws.com","box.com","boxcdn.net","cnki.net","edu.cn","eloqea.com","jingjilei.cn","wanfangdata.com.cn","sanguosha.com","yuntushuguan.com");
for (i in c) {if(shExpMatch(url.toLowerCase(),"*" + c[i].toLowerCase() + "*")){return DIRECT;};};
var b = new Array("2mdn.net",
"adbrite.com","amazon.com","archdaily.com","archdaily.net","archinect.com","armorgames.com",
"bit.ly","blogger.com","blogspot.com",
"chinagfw.org","contemporist.com",
"delicious.com","designboom.com","dwworld.de",
"facebook.com","facebook.net","fakku.net","fanjian.net","fbspin.com","fc2.com","feedburner.com","fbcdn.net","feedburner.com","flickr.com","fmpub.net","fubiz.net",
"gawker.com","google.com","gs2you.com","gstatic.com",
"hardsextube.com","hulu.com",
"igfw.net","imdb.com","inhabitat.com",
"jpg.to",
"lastpass.com","linkedin.com",
"pandora.com","p2theme.com","page2rss.com","picnik.com","photohito.com","phtolinks","pixnet.net","pornhub.com","porntube.com",
"redtube.com",
"slideshare.net","soup.io","stumbleupon.com",
"techcrunch.com","techmeme.com","t.co","treehugger.com","trendhunter.com","tumblr.com","tweetmeme.com","twimg.com","twitter.com","twitpic.com",
"vevo.com","vimeo.com","vimeocdn.com",
"wikipedia.org","wikisource.org","wretch.cc","wordpress.com",
"xuite.net","xvideos",
"youporn.com","youtu.be","youtube.com","youtubenocookie.com","ytimg.com");
for (i in b) {if(shExpMatch(url.toLowerCase(),"*" + b[i].toLowerCase() + "*")){return "PROXY 127.0.0.1:8086";};};
url = url.toLowerCase();

    for (i in gz_blacklist) { if (gz_blacklist[i].test(url)){return whitelist_check(url);};};                         //处理公用正则黑名单
    for (i in gt_blacklist) {	if (shExpMatch(url,gt_blacklist[i].toLowerCase())){return whitelist_check(url);};};     //处理公用通配符黑名单

    //处理特殊黑名单
    if (black_ad.test(url)){return white_zt_check(url, white_z_ad, white_t_ad);};                     //处理black_ad
    if (shExpMatch(url,black_union.toLowerCase())){return white_t_check(url, white_t_union);};        //处理black_union
    if (black_js.test(url)){return white_t_check(url, white_t_js);};                                  //处理black_js
    for (i in black_tvad) { if (black_tvad[i].test(url)){return white_t_check(url,white_t_tvad);};};  //处理black_tvad
    if (shExpMatch(url,black_union.toLowerCase())){return white_t_check(url, white_t_union);};        //处理black_union，误杀较多
    return ALLOW;
};

var BLOCK="PROXY 0.0.0.0";   //屏蔽广告的代理
var ALLOW="PROXY 127.0.0.1:8000"      //放行

//公用正则黑名单
var gz_blacklist = new Array(
/51\.la|51yes|cnzz\.com|linezing\.com|\/tongji\.js|google-analytics\.com\/ga\.js/i,
/(?:cbjs|spcode|eiv|drmcmm)\.baidu|\/cpro\/|pagead|\.alimama\.cn\/s?inf\.js|\.allyes\.|busjs\.vodone|icast|\/[\w]\.91wan\.com/i,
/un\.so|un\.265|imrworldwide|61ads/i,
/\/cpc\/|\.p4p\.|\/popjs|\/ghost\d[^\.]*?\.gif|\/piaofu\.gif|qqpflm|qqnews|qianming|duilian|guangg|dcads/i,
/[^eop]ads?(?:id|puba|top|flash|click|client|code|file|frame|view|img|text|info|page|sence|show|serv|ertimg|detail)/i,

//网络游戏广告
/[\.|\/](?:198game|kfwan|155game|chinaih|csyouxi|qq937|game3737|17kuxun)\./i,
//广告联盟
/cpm\.[\s\S]*?(?:RichMediaShow\.aspx|couplet\.js)|uimg\.[\s\S]*?\/jsorigin\/\d*?\.js|u\.www\.duba\.net|kingsoft\.com\/union\//i,
/[\.|\/](?:dh8866|woniu666|youxjia|k184|xp3366|116b|3393|84232|tjlove8|37see|qling|zedo|xi666|qiyou|88210212|9dcpm|778669|71aiyou|qq61|ok8848|tuigoo)\.com\//i,
/[\.|\/](?:yigao|heima8|keyrun|onetad|33hy|redu|66789|ejoina|45511|37cs|netgy|egooad|7click|8le8le|wauee|100fenlm|yiqiwin|gamediad|adsame|naqigs|vogate)\.com\//i,
/[\.|\/](?:linkunion|unionli|ylunion|adunionz|adsunion)\.com\//i,
/[\.|\/](?:77union|unionsky|joyoo|myad|pee|5622|heroclick|clickeye|cpm9v|9vcpc|9vcpm|58win|manyan|sharele|youday|ifocus|maxreturn)\.cn\//i,
/[\.|\/](?:star8|1lo0|keydot|9union)\.net\//i,
/[\.|\/](?:xsu|1133|ulink|na7|2bj|zdy)\.cc\//i,
/[\.|\/](?:leomediachina|yoyi)\.com\.cn\//i,
/union\.(?:52xiyou|pconline|114|eqifa|163|narrowad|3721|5q|qyule|yahoo|mop|51ditu|the999|lele|yesky|16tb|zhongsou)\./i,

//针对网站
/xiazaiba\.com\/js\/[\s\S]*?(?:_center|down_advert|detail_|img_text)|\/orsoon\/[\s\S]*?\.js|img\.duote\.com\/duotehtml\/gg\/down_\d\.js|7xdown\.com\/ggaotp/i,
/hanzify\.org[\s\S]*?\/a-d-s\//i,
/img\.cnbeta\.com\/\w+\d{3}\.[f-p]{3}|market\.duowan\.com|91now\.com\/down\/other\/js\/A_|newhuagg\/[\s\S]*?(?:newhua_|_bannar)[\s\S]*?\.js/i,
/\/ivy[\/\.]|pconline\.com\.cn\/(?:images\/lmt\/area_lmt|itbbs09\/js\/itbbs09_wd)\.js|piaodown\.com\/other\/js\/|img\d\.126\.net\/|d\d\.sina\.com\.cn/i,
/806\.tianya\.cn|img\.jb51\.net\/imgby\/|966\.com\/js\/msn\.js|pic\.zol-img\.com\.cn|\/g\.hsw\.cn|you85\.cn\/zhonghua\/[\s\S]*?\.js|by\.dm5\.com\/jsv2\/|cj\.qidian\.com\/Picture\//i,
/static\.ctdisk\.com\/510\.js|www\.sohu\.com\/sohuflash_\d\.js/i,

//防木马下载
/\/a*?\d\.exe/i);

//公用通配符黑名单
var gt_blacklist = new Array(
"*.crsky.com/ggao/*"
);

//公用正则白名单
var gz_whitelist =new Array(
/\.(?:taobao|tmall|tbcdn|alipay|paipai|360buy|newegg|amazon|dangdang|pceggs|unionpay)\.|qzone|mail\./i
);

//公用通配符白名单
var gt_whitelist =new Array(
"*.css",
"*.xitek.com/*/adclick.php*",
"*.3366.com/component/*adid*",
"*crsky.com/ggao/index_a.js",
"*djkk.com/ak/*",
"*.house365.com/*.html",
"*afp.120ask.*",
"*img*.126.net/caipiao/*");

//特殊黑白名单
var black_tvad = new Array(
/images\.sohu\.com\/|\.atm\.youku\.com\/|f\.youku\.com\/player\/getFlvPath\/fileid\/|asc86|pp9a|biz\d|acs\.(?:56|agent)|a\.cntv\.cn|cntv\.cn\/adplayer\/|\/adpolestar\//i,
/\.m1905.com\/uploadfile\/[\s\S]*?\.swf|cupid\.qiyi\.com|afp\.qiyi\.com\/main(?![\s\S]*?chufa)|86file\.megajoy|megajoy\.com\/toolbar\//i,
/js\.tudouui\.com\/js\/fn\/minibar_\d\.js|tdcm\.tudou\.com|v2\.tudou\.com\/tdcm\//i,
//酷6视频
/\.sdo\.com/i,
/tvbkt\.cn\/js\/cnbeta|tvbkt\.cn\/js\/tvb\/hd\d\.js|\.piaohua\.com\/[\s\S]*?_nei_|ifeng\.com\/tres\/(?:recommend|ifeng\/game)\//i);
var white_t_tvad = new Array(
"*valf.atm.youku.com*",
"*6.cn/csjs10/*.js*",
"*images.sohu.com/bill/s20*/comm/index.html" //修复搜狐的评论被误过滤 
);

var black_js =/\/\/[^\?\=]*?(?:[^egop](?:popup|tan|tanchuang|float|ads?)([^a-z][^\.\?\&\=%]*?)?|\/(?:gg|guanggao|ggao)\/[\s\S]*?|\/qq\d?|\/[a-z]|[^\d]\d{2,3}[_x\-]\d{2,3})\.js$/i;
var white_z_js = new Array(
/\.[^\/]*?\/[wx]\/[it]\.js$/i);
var white_t_js = new Array(
"*.youku.com*/a.js",       //优酷HTML5视频载入有误
"*.ct10000.com/*.popup.js*",
"*static.youku.com/*/js/popup.js*",
"*.sse.com.cn/*/sse_popup.js*",
"*.qq.com/js/*",
"*.ik123.com/js/*",
"*tv.sohu.com/upload/jq_plugin/*",  //修复搜狐视频连续剧页面不能显示剧集列表
"*tv.sohu.com/upload/*/js/g.js",     //修复搜狐视频连续剧页面不能显示分类列表
"*q.115.com/static/js/new/y.js",    //115圈子签到
"*msdn.itellyou.cn/*");

var black_ad = /[\/_\.\?\&\-]ads?[\/_\.\d\-]/i;
var white_z_ad= new Array(
/[\/_\.\?\&\-]ad\d[0-9a-f]{6}/i);
var white_t_ad = new Array(
"*/down_group*/ad/*",   //115网盘文件下载连接
"*.xunlei.com/video/js/play_ad.js*",
"*js.player.cntv.cn/*_ad.js*",
"*jxad.jx163.com/ad/jxfc/*.html",
"*.m1905.com/*",
"*flight.qunar.com/site/config/OTA_AD_CONFIG.js*");

var black_union = "*union*";
var white_t_union = new Array(
"*qilehui.com*union.js",
"*.qunar.com/*scripts/union/*",
"*union.bokecc.com/*",
"*communion.gamebar.com*",
"*.bluemov.com/e/DownSys/DownSoft*union*",
"*.tianya.cn/publicforum/*union.shtml*",
"*.10086.cn*union*",
"*bbs.voc.com.cn/*/union.js",
"*union.mapbar.com/apis/*" );


//处理公用白名单
function whitelist_check(url){
    for (i in gz_whitelist) { if (gz_whitelist[i].test(url)){return ALLOW;};};
    for (i in gt_whitelist) {	if (shExpMatch(url,gt_whitelist[i].toLowerCase())){return ALLOW;};};
    return BLOCK;
};
//处理特殊白名单(正则和通配符)
function white_zt_check(url,white_z,white_t){
    for (i in gz_whitelist) { if (gz_whitelist[i].test(url)){return ALLOW;};};
    for (i in gt_whitelist) {	if (shExpMatch(url,gt_whitelist[i].toLowerCase())){return ALLOW;};};
    for (i in white_z) { if (white_z[i].test(url)){return ALLOW;};};
    for (i in white_t) { if (shExpMatch(url,white_t[i].toLowerCase())){return ALLOW;};};
    return BLOCK;
};
//处理特殊白名单(正则)
function white_z_check(url,white_z){
    for (i in gz_whitelist) { if (gz_whitelist[i].test(url)){return ALLOW;};};
    for (i in gt_whitelist) {	if (shExpMatch(url,gt_whitelist[i].toLowerCase())){return ALLOW;};};
    for (i in white_z) { if (white_z[i].test(url)){return ALLOW;};};
    return BLOCK;
};
//处理特殊白名单(通配符)
function white_t_check(url,white_t){
    for (i in gz_whitelist) { if (gz_whitelist[i].test(url)){return ALLOW;};};
    for (i in gt_whitelist) {	if (shExpMatch(url,gt_whitelist[i].toLowerCase())){return ALLOW;};};
    for (i in white_t) {	if (shExpMatch(url,white_t[i].toLowerCase())){return ALLOW;};};
    return BLOCK;
return ALLOW;};